package com.heima.media.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.media.mapper.WmMaterialMapper;
import com.heima.media.service.WmMaterialService;
import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.PageResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.pojos.WmMaterial;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;


@Slf4j
@Service
@Transactional
public class WmMaterialServiceImpl extends ServiceImpl<WmMaterialMapper, WmMaterial> implements WmMaterialService {

   /* @Autowired
    private DfsControllerFeign dfsControllerFeign;*/

    @Autowired
    private WmMaterialMapper wmMaterialMapper;

    @Override
    public ResponseResult uploadPicture(WmMaterial material) {
       /* ResponseResult upload = dfsControllerFeign.upload(material);
        String url = upload.getData().toString();*/
        material.setUserId(1131);
        material.setCreatedTime(new Date());
        material.setIsCollection(0);
        material.setType(0);
        wmMaterialMapper.uploadPicture(material);
        return ResponseResult.okResult(null);
    }

    @Override
    public ResponseResult<WmMaterial> findPicture(Map<String, Integer> paremMap) {
        Integer page = paremMap.get("page");
        Integer size = paremMap.get("size");
        Integer isCollection = paremMap.get("isCollection");
        PageHelper.startPage(page,size);
        PageResult<WmMaterial> pageResult = new PageResult<>();
        if (null!=isCollection){
        Page<WmMaterial> materialPage= wmMaterialMapper.findPicture(isCollection);
        pageResult.setPage(page);
        pageResult.setPagesize(size);
        pageResult.setTotal(materialPage.getTotal());
        pageResult.setPages(materialPage.getPages());
        pageResult.setResult(materialPage.getResult());
        }
        return ResponseResult.okResult(pageResult);
    }
}
